<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../../static/css/public.css" media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form" lay-filter="formTest" id="form" style="width: 80%;">
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">学校</label>
			<div class="layui-input-block">
				<select name="sid" id="sid" lay-verify="required" lay-filter="sid">
					<option value="">请选择</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">专业</label>
			<div class="layui-input-block">
				<select name="did" id="did" lay-verify="required" lay-filter="did" disabled>
					<option value="">请选择</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">客户姓名</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="name" lay-verify="required" placeholder="">
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">电话</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="phone" lay-verify="phone" placeholder="">
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">qq</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="qq" lay-verify="number" placeholder="">
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">微信</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="wechat" lay-verify="number" placeholder="">
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">渠道</label>
			<div class="layui-input-block">
				<select name="cid" id="cid" lay-verify="required">
					<option value="">请选择</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">学历</label>
			<div class="layui-input-block">
				<!-- 学历：1-大专、2-本科、3-研究生、4-高中、5-中专 -->
				<select name="ectn" id="ectn" lay-verify="required">
					<option value="">请选择</option>
					<option value="1">大专</option>
					<option value="2">本科</option>
					<option value="3">研究生</option>
					<option value="4">高中</option>
					<option value="5">中专</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">届</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="period" id="period" lay-verify="required" placeholder="">
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">上课方向</label>
			<div class="layui-input-block">
				<select name="ottn" id="ottn" lay-verify="required">
					<option value="">请选择</option>
					<option value="1">前端</option>
					<option value="2">java后台</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">招生模式</label>
			<div class="layui-input-block">
				<select name="elmt" id="elmt" lay-verify="required">
					<option value="">请选择</option>
					<option value="1">社会招生</option>
					<option value="2">口碑转介绍招生</option>
					<option value="3">实训校招</option>
				</select>
			</div>
		</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<label class="layui-form-label">意向</label>
			<div class="layui-input-block">
				<select name="intt" id="intt" lay-verify="required">
					<option value="">请选择</option>
					<option value="1">有意向</option>
					<option value="2">没意向</option>
					<option value="3">潜在</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-row layui-col-xs12">
			<div class="layui-input-block">
				<button type="button" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="submit">提交</button>
				<button type="button" class="layui-btn layui-btn-sm layui-btn-primary close-btn">取消</button>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="../../../static/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layui/layui.js"></script>
	<script type="text/javascript" src="../../../static/js/index.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/constant.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/common.js"></script>
	<script type="text/javascript">
		layui.use([ 'form', 'laydate', 'layer' ], function() {
			var $ = layui.jquery;
			var form = layui.form;
			var layer = layui.layer;
			var laydate = layui.laydate;
			var selectN = layui.selectN;
			var toUpdateApi = "../../../advisory/customer/toUpdate";
			var insertApi = "../../../advisory/customer/insert";
			var updateApi = "../../../advisory/customer/update";
			var getDisciplineNameApi = "../../../advisory/customer/getDisciplineName";
			var getSchoolApi = "../../../getSchool";
			var getEmployeeApi = "../../../getEmployee";
			var getChannelApi = "../../../getChannel";
			var insertMethod = "post";
			var updateMethod = "put";
			var url = insertApi;
			var method = insertMethod;
			
			laydate.render({
				elem : '#period',//指定元素
				type: 'year' 
			});
			var id = getUrlParam("id");
			if (id) {
				//更新
				$("#did").attr("disabled",false);
				$("#form").append("<input type='hidden' name='id' value='' >");
				method = updateMethod;
				url = updateApi;
				loadAjax(layer, toUpdateApi + "/" + id, "get", null, function(response) {
					baseCallBack(response, function(response) {
						fomrVal(form, "formTest", response.data.customer);
						//获取所有学校信息
						loadAjax(layer, getSchoolApi, "get", null, function(response2) {
							baseCallBack(response2, function(response2) {
								if (response2.data && response2.data.length) {
									for(var  v  of  response2.data ){
										var selected = "";
										if(v.id==response.data.customer.sid){
											selected="selected";
										}
										$("#sid").append('<option value="'+v.id+'" '+selected+'>'+v.name+'</option>');
										form.render("select"); // 更新全部
									}
									//获取所有专业信息
									var id=response.data.customer.sid;
									loadAjax(layer, getDisciplineNameApi+"/"+id, "get", null, function(response3) {
									  baseCallBack(response3, function(response3) {
										  $("#did").empty();
										  if (response3.data && response3.data.length) {
											  $("#did").attr("disabled",false);
											  var str = '<option value="">请选择</option>';
											  for( data of response3.data){
												  var selected = "";
											 	  if(data.id==response.data.customer.did){
												  	selected="selected";
												  }
										  		  str+='<option value="'+data.id+'"'+selected+'>'+data.name+'</option>';
											  }
											  $("#did").append(str);
									      }else{
											  $("#did").attr("disabled",true);
										  }
										  form.render('select');
										  });
									});
									
									//获取所有渠道信息
									loadAjax(layer, getChannelApi, "get", null, function(response4) {
									  baseCallBack(response4, function(response4) {
										  if (response4.data && response4.data.length) {
											  var str = '';
											  for( data of response4.data){
												  var selected = "";
											 	  if(data.id==response.data.customer.cid){
												  	selected="selected";
												  }
										  		  str+='<option value="'+data.id+'"'+selected+'>'+data.name+'</option>';
											  }
											  $("#cid").append(str);
									      }else{
											  $("#cid").attr("disabled",true);
										  }
										  form.render('select');
										  });
									});
								}
							});
						});
					});
				});
			}else{
				//获取所有学校信息
				loadAjax(layer, getSchoolApi, "get", null, function(response) {
					baseCallBack(response, function(response) {
						if (response.data && response.data.length) {
							for(var  v  of  response.data ){
								$("#sid").append('<option value="'+v.id+'">'+v.name+'</option>');
								form.render("select"); // 更新全部
							}
						}
					});
				});
				//获取所有渠道信息
				loadAjax(layer, getChannelApi, "get", null, function(response4) {
				  baseCallBack(response4, function(response4) {
					  if (response4.data && response4.data.length) {
						  var str = '';
						  for( data of response4.data){
					  		  str+='<option value="'+data.id+'">'+data.name+'</option>';
						  }
						  $("#cid").append(str);
				      }else{
						  $("#cid").attr("disabled",true);
					  }
					  form.render('select');
					  });
				});
			}
			form.on('select(sid)', function(data){
				  var id= data.value?data.value:'0';
				  //获取所有专业信息
				  console.log("sda");
				  loadAjax(layer, getDisciplineNameApi+"/"+id, "get", null, function(response) {
					  $("#did").empty();
					  $("#did").attr("disabled",true);
					  baseCallBack(response, function(response) {
						  if (response.data && response.data.length) {
							  $("#did").attr("disabled",false);
							  var str = '<option value="">请选择</option>';
							  for( data of response.data){
								  str+='<option value="'+data.id+'">'+data.name+'</option>';
							  }
							  $("#did").append(str);
					      }
				  	  });
					  form.render('select');
				  });
				  form.render();
			});      
			form.on("submit(submit)", function(data) {
				loadAjax(layer, url, method, $("#form").serialize(), function(response) {
					baseCallBack(response, 

					);
				});
				return false;
			})
		})
	</script>
</body>
</html>